package com.gym.core.date;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.gym.core.date.DateContants.DateFormatType;

/**
 * 
 * @author xinchun.wang 
   @email: 532002108@qq.com
 * 2015-1-5 下午5:18:54
 */
public class DateParseUtils {
	private static final Logger logger = LoggerFactory.getLogger(DateParseUtils.class);

	public static Date convertDate(String strDate, DateFormatType dateFormatType) {
		if (StringUtils.isEmpty(strDate)|| strDate.indexOf("null") >= 0){
			return null;
		}
		Date date = null;
		try {
			SimpleDateFormat fmt = DateContants.getDateFormat(dateFormatType);
			synchronized(fmt){
				date = fmt.parse(strDate);
			}
		} catch (Exception e) {
			logger.error("convertLong error: date="+strDate, e);
		}

		return date;
	}
}
